package com.jj.controller;

import com.jj.dto.ProductTypeWithProductsDTO;
import com.jj.entity.ProductTypes;
import com.jj.service.ProductTypeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/productType")
public class ProductTypeController {
    @Autowired
    private ProductTypeService productTypeService;

    @RequestMapping("/selectById")
    public ProductTypes selectById(@Param("typeId") Integer typeId){
        return productTypeService.selectById(typeId);
    }

    @RequestMapping("/selectAll")
    public List<ProductTypes> selectAll(){
        return productTypeService.selectAll();
    }

    @RequestMapping("/insert")
    public int insert(ProductTypes productType){
        return productTypeService.insert(productType);
    }

    @RequestMapping("/update")
    public int update(ProductTypes productType){
        return productTypeService.update(productType);
    }

    @RequestMapping("/deleteById")
    public int deleteById(@Param("typeId") Integer typeId){
        return productTypeService.deleteById(typeId);
    }

    @RequestMapping("/selectByTypeName")
    public ProductTypes selectByTypeName(@Param("typeName") String typeName){
        return productTypeService.selectByTypeName(typeName);
    }

    @RequestMapping("/selectTypeWithProducts")
    public ProductTypeWithProductsDTO selectTypeWithProducts(@Param("typeId") Integer typeId){
        return productTypeService.selectTypeWithProducts(typeId);
    }
}
